package com.example.champtionthree.model;

import com.example.champtionthree.api.IService;
import com.example.champtionthree.bean.ExamInfo;
import com.example.champtionthree.view.ExamFragment;
import com.example.common.ICommonModel;
import com.example.common.ICommonPresenter;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class TestModel implements ICommonModel {


    @Override
    public void getData(final int whichApi, final int loadType, final ICommonPresenter commonPresenter, final Object[] pP) {
        Retrofit build = new Retrofit.Builder()
                .baseUrl("https://www.google.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        Observable<ExamInfo> examInfo = build.create(IService.class).getExamInfo("http://apie.ergedd.com/api/v1/album_categories?channel=new&off set=0&limit=100&addition_album_count=20");
        examInfo.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ExamInfo>() {
                    @Override
                    public void accept(ExamInfo examInfo) throws Exception {
                        commonPresenter.onSuccess(whichApi, loadType, examInfo);

                    }

                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        commonPresenter.onFailed(throwable);
                    }
                });
    }
}

